import { createApp } from 'vue'
import App from './views/Article.vue'
import './registerServiceWorker'
import { Button, Card, Divider, List, Sticky, Uploader, Form, Field, CellGroup, Dialog, Tab, Tabs, Toast } from 'vant'
import './assets/less/global.less'
import request from './utils/request'

const wx = window.wx

request.get('/mp/getWxJsapi').then(res => {
  if (res) {
    wx.config({
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
      appId: res.appId, // 必填，公众号的唯一标识
      timestamp: res.timestamp, // 必填，生成签名的时间戳
      nonceStr: res.nonceStr, // 必填，生成签名的随机串
      signature: res.signature, // 必填，签名
      jsApiList: [
        // 所有要调用的 API 都要加到这个列表中
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'onMenuShareQZone',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'translateVoice',
        'startRecord',
        'stopRecord',
        'onVoiceRecordEnd',
        'playVoice',
        'onVoicePlayEnd',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openCard'
      ] // 必填，需要使用的JS接口列表
    })
    wx.ready(function () {
      wx.updateAppMessageShareData({
        title: '你拍我查', // 分享标题
        desc: '文章列表', // 分享描述
        link: location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: location.origin + '/logo.jpg', // 分享图标
        success: function () {
          console.log('设置成功')
        }
      })
    })
  } else {
    Toast(res.msg)
  }
})

createApp(App)
  .use(Button)
  .use(Uploader)
  .use(Card)
  .use(Divider)
  .use(List)
  .use(Sticky)
  .use(Form)
  .use(Field)
  .use(CellGroup)
  .use(Dialog)
  .use(Tab)
  .use(Tabs)
  .mount('#app')
